package com.df.springmvc.supper;

import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.common.bean.DhtmlGridBean;
import com.df.springmvc.common.bean.CurrentUserBean;

public abstract class SupperServices implements SupperServicesI{
	public String path;
	public String webPath;
	{
		this.getClass().getResource("/").getHost();
		path=URLDecoder.decode(SupperServices.class.getClassLoader().getResource("").getPath());
		webPath=path.replace("\\","/").replace("/WEB-INF/classes","");
	}
	HttpServletRequest request;
	HttpServletResponse response;
	final static public String Add="Add";
	final static public String Upd="Upd";
	final static public String Del="Del";
	final static public String View="View";
	final static public String toAdd="toAdd";
	final static public String toUpd="toUpd";
	final static public String toDel="toDel";
	final static public String toView="toView";
	final static public String doAdd="doAdd";
	final static public String doUpd="doUpd";
	final static public String doDel="doDel";
	final static public String doView="doView";
	
	public HttpServletRequest getRequest(){
		return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	}
	public HttpSession getSession(){
		return getRequest().getSession();
	}
	/**
	 * 增加RequestAttribute
	 * @param key
	 * @param value
	 */
	public void addRequestAttribute(String key,Object value){
		getRequest().setAttribute(key,value);
	}
	/**
	 * 增加SessionAttribute
	 * @param key
	 * @param value
	 */
	public void addSessionAttribute(String key,Object value){
		getSession().setAttribute(key,value);
	}
	/**
	 * 获取当前用户
	 * @return
	 */
	public CurrentUserBean getCurrentUserBean(){
		if(getSession().getAttribute("CurrentUserBean") != null){
			return (CurrentUserBean)getSession().getAttribute("CurrentUserBean");
		}else{
			return new CurrentUserBean();
		}
	}
	/**
	 * /**
	 * 传入DhtmlGridBean,与参数Map,返回DhtmlGridBean
	 */
	@Override
	public DhtmlGridBean query(DhtmlGridBean gridBean,HashMap<String,String> paramMap) throws Exception{
		// TODO Auto-generated method stub
		return gridBean;
	}
	// /////////////////////////
	@Override
	public Object add(HashMap<String,String> paramMap) throws Exception{
		return "OK";
		// TODO Auto-generated method stub
	}
	@Override
	public Object upd(HashMap<String,String> paramMap) throws Exception{
		// TODO Auto-generated method stub
		return "OK";
	}
	@Override
	public Object del(HashMap<String,String> paramMap) throws Exception{
		// TODO Auto-generated method stub
		return "OK";
	}
	@Override
	public HashMap<String,Object> view(String guid) throws Exception{
		// TODO Auto-generated method stub
		return null;
	}
}
